package com.bw.user.mvvm.view.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.bw.greendao.dao.DaoSessionUtils;
import com.bw.greendao.entity.UserDaoEntity;
import com.bw.greendao.entity.UserEntity;
import com.bw.user.R;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

public class SetsActivity extends AppCompatActivity {

    private Button exitBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sets);
        initView();

        exitBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<UserEntity> userEntities = new UserDaoEntity().selectAll();
                for (UserEntity userEntity : userEntities) {
                    if (userEntity.getFlag()){
                        userEntity.setFlag(false);
                        new UserDaoEntity().updata(userEntity);
                    }
                }

                EventBus.getDefault().post("登录/注册");
                finish();
            }
        });
    }

    private void initView() {
        exitBtn = (Button) findViewById(R.id.exit_btn);
    }
}